<template>
	<view class="register">
		<view class="top">
			<img src="../../static/login_logo.png" mode=""></img>
		</view>
		<view class="inputWrap bgw pd30">
			<view class="input">
				<view class="inputLeft">
					<view class="title">姓名</view>
					<input type="text" v-model="name" placeholder="请输入姓名" placeholder-class="pcs" />
				</view>
			</view>
			<view class="input">
				<view class="inputLeft">
					<view class="title">手机号码</view>
					<input type="number" v-model="phone" placeholder="请输入手机号码" placeholder-class="pcs" />
				</view>
			</view>
			<view class="input">
				<view class="inputLeft">
					<view class="title">性别</view>
					<picker @change="bindPickerChange" :value="index" :range="array">
						<view class="pcs" v-if="index === -1">请选择性别</view>
						<view class="pickerInput" v-else>{{array[index]}}</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="uniBtn">
			<view @click="bang(1)">用户绑定</view>
			<!-- <view @click="bang(2)">医生绑定</view> -->
		</view>
		<view class="btnStyle" @click="submit">注册</view>
	</view>
</template>

<script>
	import {register} from '@/request/api.js'
	export default {
		data() {
			return {
				array: ['男', '女'],
				index: -1,
				name: '',
				phone: '',
				sex:'' 
			}
		},
		onLoad() {
			
		},
		methods: {
			bindPickerChange(e) {
				this.index = e.target.value
				this.sex = Number(e.target.value)+1
			},
			bang(num){
				if(num == 1){
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}else if(num == 2){
					uni.navigateTo({
						url:'/pages/login/login2'
					})
				}
			},
			submit(){
				if(!this.name) {
					uni.showToast({
						title: '请输入姓名',
						icon: "none"
					})
					return
				}
				if(!/^1[3456789]\d{9}$/.test(this.phone)) {
					uni.showToast({
						title: '手机号格式不正确',
						icon: "none"
					})
					return
				}
				if(!this.sex) {
					uni.showToast({
						title: '请选择性别',
						icon: "none"
					})
					return
				}
				let param = {
					pid:uni.getStorageSync('pid'),
					company_id:uni.getStorageSync('companyId'),
					openid:uni.getStorageSync('openid'),
					name:this.name,
					phone:this.phone,
					sex:this.sex
				}
				register(param).then(res=>{
					if(res.data.member){
						uni.setStorageSync('member',res.data.member)
					}
					if(res.data.doctor){
						uni.setStorageSync('doctor',res.data.doctor)
					}
					uni.showModal({
						title: '提示',
						content: '注册成功,登录密码为您的手机号码后六位！',
						showCancel: false, //没有取消按钮的弹框
						success: function(ret) {
							if (ret.confirm) {
								uni.setStorageSync('token',res.data.member.login_token)
								uni.setStorageSync('identity',1)//当前登录身份 1 用户  2 医生
								uni.reLaunch({
									url:'/pages/index/index'
								})
							}
						}
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #f8f8f8;
	}
	.register {
		.top{
			background: #ffffff;
			img {
				width: 500upx;
				height: 500upx;
				margin-bottom: 34upx;
				display: block;
				margin: 0 auto;
			}
		}
		
		.inputWrap {
			.input {
				height: 96upx;
				border-bottom: 1px solid #E5E5E5;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.inputLeft {
					display: flex;
					align-items: center;

					.title {
						width: 140upx;
						font-size: 28upx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						line-height: 40px;
						color: #414141;
						margin-right: 40upx;
					}
					.pickerInput {
						font-size: 28upx;
						line-height: 96upx;
					}
				}
			}

			.input:last-of-type {
				border: none;
			}
		}
		.uniBtn{
			font-size: 28upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #9F9F9F;
			padding: 36upx;
			color: #6996FE;
			margin-bottom: 36upx;
		}
	}
</style>
